package cn.fintecher.pangolin.service.manage.request;

import cn.fintecher.pangolin.common.enums.BaseSelect;
import cn.fintecher.pangolin.common.enums.BaseStatus;
import cn.fintecher.pangolin.entity.mysql.QRole;
import com.querydsl.core.BooleanBuilder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;


@Data
public class RoleRequest {

    private String roleName;

    private BaseStatus status;

    public BooleanBuilder generateBooleanBuilder() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        booleanBuilder.and(QRole.role.isSystem.eq(BaseSelect.NO));
        if (StringUtils.isNoneBlank(roleName)) {
            booleanBuilder.and(QRole.role.name.like(StringUtils.join(roleName, "%")));
        }
        if (Objects.nonNull(status)) {
            booleanBuilder.and(QRole.role.status.eq(status));
        }
        return booleanBuilder;
    }
}
